//
//  UserTableViewCell.m
//  TourPlay
//
//  Created by dllo on 15/11/30.
//  Copyright © 2015年 王军岐. All rights reserved.
//

#import "UserTableViewCell.h"

@interface UserTableViewCell ()

@property (nonatomic, retain) UILabel *titleL;

@property (nonatomic, retain) UIImageView *rightImageV;
@property (nonatomic, retain) UISwitch *mySwitch;


@end

@implementation UserTableViewCell
- (void)dealloc
{
    [_titleL release];
    [_lineV release];
    [_rightImageV release];
    [_mySwitch release];
    [_tempL release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}
- (void)createSubViews
{
    self.titleL = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 100, 44)];
    self.titleL.text = @"夜间模式";
//    self.titleL.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:self.titleL];
    [_titleL release];
    


    [self addColorChangedBlock:^{
        
        self.titleL.normalTextColor = [ColorSingleton shareSingleton].cellTitleColor;
        self.titleL.nightTextColor = [ColorSingleton shareSingleton].cellTitleColor;
        
    }];
}
- (UISwitch *)mySwitch
{
    if (nil == _mySwitch) {
        self.mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 70, 7, 50, 30)];
        // 打开的颜色
        self.mySwitch.onTintColor = [UIColor lightGrayColor];
        // 关闭颜色
        //    self.mySwitch.tintColor = [UIColor brownColor];

        //    [self.mySwitch setOn:YES animated:YES];
        if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"isNight"] isEqualToString:@"1"]) {
            self.mySwitch.on = YES;
        } else {
            self.mySwitch.on = NO;
        }
        
        [self.mySwitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _mySwitch;
}
- (UIImageView *)rightImageV
{
    if (nil == _rightImageV) {
        self.rightImageV = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 30, 15, 14, 14)];
        self.rightImageV.image = [UIImage imageNamed:@"iconfont-svg02.png"];

    }
    return _rightImageV;
}
- (UIView *)lineV
{
    if (nil == _lineV) {
        self.lineV = [[UIView alloc] initWithFrame:CGRectMake(self.titleL.frame.origin.x, self.titleL.frame.size.height - 1, SCREEN_WIDTH - self.titleL.frame.origin.x, 1)];
        self.lineV.backgroundColor = [UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1];

    }
    return _lineV;
}
- (UILabel *)tempL
{
    if (nil == _tempL) {
        self.tempL = [[UILabel alloc] initWithFrame:CGRectMake(self.rightImageV.frame.origin.x - 70, 0, 70 * AUTOSCREEN_WIDTH, 44)];
//        self.tempL.backgroundColor = [UIColor orangeColor];
        self.tempL.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:self.tempL];
        [_tempL release];
    }
    return _tempL;
}
- (void)setValueWithIndexPath:(NSIndexPath *)indexPath
{
    if (0 == indexPath.section) {
        self.titleL.text = @"夜间模式";
        [self.contentView addSubview:self.mySwitch];
        
        NSLog(@"---%ld", self.mySwitch.retainCount);
        [_mySwitch release];
    } else {
        
        [self.contentView addSubview:self.rightImageV];
        [_rightImageV release];
        
        
        if (1 == indexPath.section) {
            
            
            if (indexPath.row < 2) {
                
                if (0 == indexPath.row) {
                    self.titleL.text = @"我的收藏";
                } else {
                    self.titleL.text = @"浏览历史";
                }
                
                
                [self.contentView addSubview:self.lineV];
                [_lineV release];
            } else {
                
                self.titleL.text = @"清除缓存";
//                self.tempL.text = @"fefe";
            }
        } else {
            self.titleL.text = @"关于我们";
        }

    }
}
- (void)switchAction:(UISwitch *)sender
{
    if (sender.isOn) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"isNightChange" object:@"1"];
        [DKNightVersionManager nightFalling];
    } else {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"isNightChange" object:@"0"];
        [DKNightVersionManager dawnComing];
    }
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
